#include <iostream>
#include <string>
#include <stack>

// 函数将10进制数num转换为指定进制base的字符串表示
std::string decimalToBase(int num, int base) {
    // 非法输入检查
    if (num < 0 || base < 2 || base > 16) {
        return "Invalid input";
    }

    // 对于0，直接返回0
    if (num == 0) {
        return "0";
    }

    // 用于存储结果的栈
    std::stack<char> resultStack;

    // 数字字符映射表
    const char digitMap[] = "0123456789ABCDEF";

    // 转换为指定进制
    while (num > 0) {
        int remainder = num % base;
        resultStack.push(digitMap[remainder]);
        num /= base;
    }

    // 构建结果字符串
    std::string result = "";
    while (!resultStack.empty()) {
        result += resultStack.top();
        resultStack.pop();
    }

    return result;
}

int main() {
    
    int decimalNumber; // 10进制数
    std::cin>>decimalNumber;
    int base;           // 目标进制
    std::cin>>base;

    std::string result = decimalToBase(decimalNumber, base);
    std::cout << decimalNumber << " in base " << base << " is: " << result << std::endl;

    return 0;
}


//char digitChar = (remainder < 10) ? ('0' + remainder) : ('A' + remainder - 10);
//适用于进制在2~36之间的情况
